package com.dmooo.ymx.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dmooo.ymx.R;
import com.dmooo.ymx.bean.Xuanpinkbean;
import com.dmooo.ymx.common.SPUtils;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 开发者：陈飞
 * 时间:2018/7/26 14:34
 * 说明：子适配器
 */
public class XuanpinkAdapter extends CommonAdapter<Xuanpinkbean> {
    SpannableString spannableString;
    Drawable drawable;
    DecimalFormat df=new DecimalFormat("0.00");
    public XuanpinkAdapter(Context context, int layoutId, List<Xuanpinkbean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, Xuanpinkbean item, int position) {
        //设置图片
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(item.pict_url+"_310x310.jpg").placeholder(R.drawable.no_banner).dontAnimate().into(imageView);
        ((TextView)holder.getView(R.id.title_child)).setText(item.title);
        //券后
        holder.setText(R.id.tx2, "￥" + df.format(Double.valueOf(item.zk_final_price)- Double.parseDouble(item.coupon_amount)) );
        //券后2
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText( item.zk_final_price);
//        TextView tvhehe = holder.getView( R.id.hehejiage );
//        tvhehe.setText("升级分享最高可赚:￥" + df.format((Double.valueOf(item.zk_final_price)- Double.parseDouble(item.coupon_amount))*Double.parseDouble( item.tk_rate )/100* Double.parseDouble(df.format((float) SPUtils.getIntData(mContext, "rate", 0) / 100))) );
        //内部
        TextView tx3 = holder.getView(R.id.tx3);
        tx3.setText(item.coupon_amount + "元");
        holder.setText(R.id.tx4, "预估省:"+df.format((Double.valueOf(item.zk_final_price)- Double.parseDouble(item.coupon_amount))*Double.parseDouble( item.tk_rate )/100* Double.parseDouble(df.format((float) SPUtils.getIntData(mContext, "rate", 0) / 100))+Double.valueOf(item.coupon_amount)));
        holder.setText(R.id.tx5, "已售:"+item.volume);
    }
}
